'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller, middleware } = app;
  const { sign, auth, rbac } = middleware;

  // 是否开启API签名验证
  const enableRSAChecker = false;

  // 注意中间件的执行顺序
  const checks = enableRSAChecker ? [sign(), auth(), rbac()] : [auth()];

  // 上传
  router.post('/api/upload/file', controller.upload.file);

  // 登录
  if (enableRSAChecker) {
    router.post('/api/member/login', sign(), controller.member.login);
  } else {
    router.post('/api/member/login', controller.member.login);
  }
  router.post('/api/member/register', controller.member.create);
  // device
  router.get('/api/device/list', controller.device.allList);
  // 连接设备
  router.post('/api/device/collect', controller.device.collect);
    // 更新设备启用状态
    router.put('/api/device/enable', controller.device.enable);
  router.resources('device', '/api/device', controller.device);
  // connection_history
    router.post('/api/connectionHistory/list', controller.connectionHistory.allList);
    router.resources('connectionHistory', '/api/connectionHistory', controller.connectionHistory);
    // enable_history
    router.post('/api/enableHistory/list', controller.enableHistory.allList);
    router.resources('enableHistory', '/api/enableHistory', controller.enableHistory);
    // 设备数据
    router.post('/api/deviceData/list', controller.deviceData.allList);
    router.resources('deviceData', '/api/deviceData', controller.deviceData);
  // 会员
  router.get('/api/member/list', controller.member.allList);
  router.resources('member', '/api/member', controller.member);
  // 用户咨询
  router.get('/api/consult/list', controller.consult.allList);
  router.resources('consult', '/api/consult', controller.consult);
  // 评论
  router.get('/api/comment/list', controller.comment.allList);
  router.resources('comment', '/api/comment', controller.comment);
  // 新闻
    router.get('/api/news/list', controller.news.allList);
    router.resources('news', '/api/news', controller.news);
};
